/**
 * Main activity class for Flashlight+
 *
 * LICENSE: This source file is subject to the MIT License, available
 * at http://www.opensource.org/licenses/mit-license.html
 *
 * @author     Jayson Schmidt <jayson@888mobileapps.com>
 * @copyright  2013 888MobileApps
 * @license    http://www.opensource.org/licenses/mit-license.html
 */

package com.threeeightmobileapps.flashlightplus;

import android.graphics.Color;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.widget.ToggleButton;

public class MainActivity extends Activity {

	private boolean isOn = false;
	private Button flashlight, strobe, code;
	
	private Context context;
	private PackageManager pm;
	private Parameters p;
	
	private FlashlighPlusController flpc;
	
	public void setMode(View view) {
		if(view.getId() == R.id.flashlightButton) {
			flpc.setMode(1);
			flashlight.setBackgroundColor(Color.LTGRAY);
			strobe.setBackgroundColor(Color.DKGRAY);
			code.setBackgroundColor(Color.DKGRAY);
		}else if(view.getId() == R.id.strobeButton) {
			flpc.setMode(2);
			flashlight.setBackgroundColor(Color.DKGRAY);
			strobe.setBackgroundColor(Color.LTGRAY);
			code.setBackgroundColor(Color.DKGRAY);
		}else {
			flpc.setMode(3);
			flashlight.setBackgroundColor(Color.DKGRAY);
			strobe.setBackgroundColor(Color.DKGRAY);
			code.setBackgroundColor(Color.LTGRAY);
		}
	}
	
	private void initUI() {
		flashlight = (Button)findViewById(R.id.flashlightButton);
		flashlight.setBackgroundColor(Color.LTGRAY);
		flashlight.setTextColor(Color.WHITE);
		strobe = (Button)findViewById(R.id.strobeButton);
		strobe.setBackgroundColor(Color.DKGRAY);
		strobe.setTextColor(Color.WHITE);
		code = (Button)findViewById(R.id.codeButton);
		code.setBackgroundColor(Color.DKGRAY);
		code.setTextColor(Color.WHITE);
		flpc = (FlashlighPlusController)findViewById(R.id.flashlighPlusController);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		initUI();
		flpc.init();
		
		
	}
	
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
	    super.onConfigurationChanged(newConfig);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
